package cn.edu.ctbu.myblog.webapi;

import cn.edu.ctbu.myblog.domain.ArticleDO;
import cn.edu.ctbu.myblog.service.ArticleService;
import cn.edu.ctbu.myblog.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("webapi/blog/article")
public class ArticleRestController {

    @Autowired
    ArticleService articleService;


    @RequestMapping("/list")
    public List<ArticleDO> getAll(){

        List<ArticleDO> articleDOS=articleService.getAll();
        return  articleDOS;

    }

    @PostMapping("/insert")
    public void addArticle(HttpServletRequest htttprequest,String title,String content){
        HttpSession session=htttprequest.getSession();
        int userId=(int)session.getAttribute("userId");
        articleService.addArticle(title,content,0,userId);
    }

    @PostMapping("/findBytTitle")
    public List<ArticleDO> findByTitle(String title){
        List<ArticleDO> articleDOS=articleService.getByTitle(title);
        return articleDOS;
    }

    @PostMapping("/giveGood")
    public void giveGood(String id){
        articleService.giveGood(id);
    }
}
